<template>
	<view>
		<uni-section title="搜索" type="line">
			<uni-search-bar @confirm="search" :focus="true" v-model="params.num" @blur="blur" 
				@cancel="cancel" @clear="clear">
			</uni-search-bar>
		</uni-section>
		<uni-section title="任务列表" type="line">
			<uni-list>
				<uni-list-item v-for="(item, i) in list" :key="i" clickable
					:title="item.num" :note="item.remark" show-arrow @click="showDetail(item)"
					:rightText="item.createTime">			
				</uni-list-item>
			</uni-list>
		</uni-section>
		<uni-load-more :status="moreStatus" @clickLoadMore="getList"/>
	</view>
</template>

<script>
	import {listMyStock, updateStock} from '@/api/stock.js'
	export default {
		components: {},
		data() {
			return {
				list:[],
				moreStatus:'noMore',
				params:{
					num:null,
					pageSize: 10,
					pageNum: 1,
					orderByColumn: 't.id',
					isAsc: 'DESC'
				}
			}
		},
		onLoad() {
			this.getList();
		},
		methods: {
			getList() {
				this.moreStatus = 'loading';
				listMyStock(this.params).then(response=>{
					this.list = response.rows;
					if(response.total > this.params.pageNum * this.params.pageSize){
						this.moreStatus = 'more';
						this.params.pageNum += 1;
					}else{						
						this.moreStatus = 'noMore';
					}
				})
			},
			search(res) {
				this.params.pageNum = 1;
				this.getList();
			},
			clear(res) {
				this.params.pageNum = 1;
				this.getList();
			},
			blur(res) {
				this.params.pageNum = 1;
				this.getList();
			},
			showDetail(item) {	
				this.$tab.navigateTo('/pages/stock/task?id='+item.id);
				/*
				console.log(item)
				if(item.status == '0'){
					this.$modal.confirm('当前盘点任务还没有开始，您是否要开始进行盘点？').then(function(){
						item.status = '1';
						updateStock(item).then(response=>{
							this.gotoAction(item, 'stock')
						});
					});
				}if(item.status == '0'){
					this.gotoAction(item, 'stock')
				}else{
					this.gotoAction(item, 'view')
				}
				*/
			},
			gotoAction(item, action) {
				let url = '/pages/stock/list?stockId='+item.id+'&action='+action;
				this.$tab.navigateTo(url);
			}
		}
	}
</script>

<style>
	.uni-common-mt {
		margin-top: 10px;
	}

	.uni-padding-wrap {
		// width: 750rpx;
		padding: 0px 10px;
	}
</style>